package servlet;

import pojo.Music;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import utils.MybatsUtils;

import java.io.IOException;

import java.util.List;

//开启页面查询所有的音乐的逻辑
// 刘小文  -2420710103---
@WebServlet("/showAllMusics")
public class ShowAllMusicsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws  IOException {

        //1 使用Mybatis将查询所有音乐信息

        List<Music> userList = MybatsUtils.selectList("MusicMapper.findAll");
        //2 将查询到的音乐信息保存到session中
        HttpSession session = request.getSession();
        session.setAttribute("allMusics", userList);
        //3 页面跳转到 musics.jsp
        response.sendRedirect("Music.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request,response);
    }
}
